﻿/*
 * Created by SharpDevelop.
 * User: Intel
 * Date: 29.11.2014
 * Time: 12:28
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace Region
{
  /// <summary>
  /// Description of OtdelSelector.
  /// </summary>
  public partial class OtdelSelector : UserControl
  {
    OtdelSelectorForm form;
    protected Engine m_engine;
    protected OtdelList m_otdelList; 
    protected Int32 m_OtdelID = 13;
    public Engine engine{get{return m_engine;}set{m_engine=value;onchange();}}
    public OtdelList otdelList{get{return m_otdelList;}set{m_otdelList=value;onchange();}}
    public Int32 OtdelID{get{return m_OtdelID;}set{m_OtdelID=value;onchange();}}
    public delegate void EventHandlerOnSelectOtdel(Int32 OtdelID);    
    public event EventHandlerOnSelectOtdel OnSelectOtdel;
    protected void onchange()
    {
      if (m_engine==null) return;
      form.engine = m_engine;
      form.otdelList = m_otdelList;
      form.OtdelID = m_OtdelID;
      button1.Text = (m_OtdelID>0)?m_engine.getOtdel(m_OtdelID).OtdelName:"[не выбран]";
    }
    protected void changeOtdelID(Int32 OtdelID)
    {
      if (m_OtdelID == OtdelID) return;
      m_OtdelID = OtdelID;
      button1.Text = (m_OtdelID>0)?m_engine.getOtdel(m_OtdelID).OtdelName:"[не выбран]";  
      if (OnSelectOtdel!=null) 
        OnSelectOtdel(m_OtdelID);      
    }    
    public OtdelSelector()
    {
      //
      // The InitializeComponent() call is required for Windows Forms designer support.
      //
      InitializeComponent();
      
      //
      // TODO: Add constructor code after the InitializeComponent() call.
      //
      form = new OtdelSelectorForm();
      form.OnSelectOtdel += changeOtdelID;    
    }
		void Button1Click(object sender, EventArgs e)
		{
		  if (otdelList==null) otdelList = new OtdelList(engine);
		  form.Location = this.PointToScreen(new Point(0,this.Height));
		  form.ShowList();
		  //form.Location = this.PointToScreen(new Point(0,this.Height));
		    return;
		}    
  }
}
